package com.outlook.flowervowlogin;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.Map;

public class CommandCaptcha implements CommandExecutor {
    static Map<Player,String> CAPTCHA = new HashMap<>();
    private Main plugin;
    public CommandCaptcha(Main plugin){
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {

        Player p = (Player) commandSender;
        if (command.getName().equalsIgnoreCase("captcha")) {
            if (args.length == 1) {
                String word = args[0];
                if (word.equalsIgnoreCase(CAPTCHA.get(p))) {

                    CAPTCHA.remove(p);
                    EventJoin.TASK.get(p).cancel();
                    EventJoin.TASK2.get(p).cancel();
                    p.sendMessage("§a[§a茶§b坂]§a验证通过！请输入§b/reg [密码] [重复密码]§a来注册/或输入§b/l [密码] §a来登录你的账号");

                } else {
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            p.kickPlayer("§a[§a茶§b坂]§c验证码错误！！！");
                        }
                    }.runTaskLater(plugin, 10);
                }
            }
        }
        return true;
    }
}
